package store

import (
	"io"
	"log"
	"os"
)

type Logger struct {
	log *log.Logger
}

var Log *Logger

func NewLogger(path string) (*Logger, error) {
	file, err := os.OpenFile(path, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		return nil, err
	}
	return &Logger{
		log: log.New(io.MultiWriter(file, os.Stdout), "", log.LstdFlags),
	}, nil
}

func (l *Logger) Info(key string, v ...interface{}) {
	l.log.Printf("[INFO] # %s # %v\n", key, v)
}

func (l *Logger) Panic(key string, v ...interface{}) {
	l.log.Panicf("[Panic] # %s # %v\n", key, v)
}

func (l *Logger) Fatal(key string, v ...interface{}) {
	l.log.Fatalf("[Fatal] # %s # %v\n", key, v)
}
